请求输入然后在新 window 中打开

Ask for input then open in new window

我不太了解 Java脚本 所以我只是想知道是否可以弹出 Java 警报要求 URL 然后设置到 URL 的 iframe 弧(这将 运行 作为书签)。

基本上,我正在寻找一个弹出提示,要求 url 然后打开一个新的 window 并在新的 window 中创建一个 iframe打字较早 l.

javascript:

    var win = window.open();
    win.document.write('<style>body {margin: 0;}</style>
                       <iframe width="100%" height="100%" src="//bing.com" frameborder="0" 
                       sandbox="allow-forms allow-pointer-lock allow-same-origin allow-scripts">
                       </iframe>');

提前致谢!

可以,你可以使用自调用函数来封装脚本:

javascript: (function() {
var alertWinRes  =  prompt("Please enter Site", "bing.com");
if(alertWinRes !== null){
   var win = window.open("My new Window"); 
   win.document.write('<style>body {margin: 0;} 
   </style><iframe width="100%" height="100%" src="//' + alertWinRes + 
   '" frameborder="0" sandbox="allow-forms                        
   allow-pointer-lock allow-same-origin allow-scripts"></iframe>');     
 }
})();

不用 iframe 也能实现同样的功能:

javascript: (function() {
var alertWinRes  =  prompt("Please enter Site", "bing.com");
if(alertWinRes !== null){
   var win = window.open("https://" + alertWinRes, "_blank");     
}
})();

使用提示创建用户可以用来输入文本的警报,第二个参数用于设置默认值。您必须打开网站才能触发此操作,出于安全原因,在新选项卡中它不起作用(如果需要,在线发布了有关它的解决方法)。