Javascript警报显示网站网址。如何从javascript警报顶部删除网站网址? [英] Javascript alert showing site url. How can i remove site url from top of javascript alert?

查看:111
本文介绍了Javascript警报显示网站网址。如何从javascript警报顶部删除网站网址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

javascript警告框显示网址+消息。我没有通过任何东西,但它显示警报框顶部的网址。我怎么能删除这个网址?当我的网站从另一个网站重定向时,该网址会显示。

javascript alert box showing url + msg. i have not passed any thing but it shows url on the top of alert box. how can i remove this url ? The url is showing when my site is redirected from another site.

意味着从abc.com重定向到xyz.com和警告框显示xyz.com + msg?

Means redirect from abc.com to xyz.com and alert box showing xyz.com + msg ?

推荐答案


如何从javascript警报顶部删除网站网址?

How can i remove site url from top of javascript alert?



<你不能。浏览器添加该内容,以便用户知道该消息不是来自浏览器本身。

You can't. The browser adds that so that the user knows that the message isn't from the browser itself.

您唯一能做的就是停止使用完全警告,而是使用现代技术在页面顶部覆盖元素。您可以自己编写,也可以使用其中的任何lightbox库。请注意,这样做会改变您对代码进行编码的方式,因为当 alert (以及确认提示)当页面上的脚本执行时,它们会在屏幕上暂停,你不能在自己的代码中执行此操作,因此必须构建代码以便在它接收用户解雇该框的事件。通常库会给你一个你可以使用的回调,例如这个 alert 代码:

The only thing you can do is stop using alert entirely, and instead use modern techniques for overlaying an element on top of the page. You can write this yourself, or use any of the many "lightbox" libraries out there. Note that doing so changes how you code things a bit, because while alert (and confirm and prompt) bring execution of scripts on the page to a screeching halt while they're on-screen, you can't do that in your own code, so you have to structure your code to continue when it receives the event that the user dismissed the box. Usually the library will give you a callback you can use for that, so for instance this alert code:

function foo() {
    doSomething();
    alert("Foo!");
    if (x != 42) {
        doSomethingElse();
    }
}

变为

function foo() {
    doSomething();
    someNiftyLightboxThingy("Foo!", function() {
        if (x != 42) {
            doSomethingElse();
        }
    });
}

不难,你只需要习惯它。

Not hard, you just have to get used to it.

你没有拥有来使用库,但这样做可以让你不用担心边缘情况,并可能为你提供更多功能。这是一个相当简单的例子:

You don't have to use a library for this, but doing so lets you not worry about edge cases and may offer you more features. Here's a fairly bare-bones example:

HTML:

<input type='button' id='btnPopup' value='Click for Pop-Up'>

CSS:

iframe.shim {
  width:            100%;
  height:           100%;
  position:         absolute;
  left:             0px;
  top:              0px;
  z-index:          100;
  background-color: #fff;
  opacity:          0.5;                 /* Standard */
  filter:           alpha(opacity = 50); /* For IE */
}
div.overlay {
  z-index:          101;
  border:           1px solid black;
  background-color: #ecc;
  position:         absolute;
  left:             100px;
  top:              100px;
}

JavaScript:

JavaScript:

function doVerySimplePopup(text, callback) {
  var shim, div, parent = document.body;

  shim = document.createElement('iframe');
  shim.className = 'shim';
  parent.appendChild(shim);

  div = document.createElement('div');
  div.className = 'overlay';
  div.innerHTML = text;
  parent.appendChild(div);
  div.onclick = function() {
    parent.removeChild(div);
    parent.removeChild(shim);
    if (typeof callback === "function") {
      try { callback(); } catch (e) { }
    }
  };
}

实例

显然你想要稍微调整一下,再次,这是一个简单的例子,而不是一个完整的解决方案。

Obviously you'd want to tart that up a bit, and again, this is a bare-bones example, not a complete solution.

这篇关于Javascript警报显示网站网址。如何从javascript警报顶部删除网站网址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆