【发布时间】:2017-05-25 21:24:04
【问题描述】:
我是一个相当新的程序员,我需要一个建议,我如何才能做到这一点,
我的目标是能够在新窗口中打开一个新网站,例如 google.com,并在搜索输入框中输入一个字符串,而无需用户执行任何操作。
我已经看过很多想法如何实现,但似乎没有找到我可以使用的解决方案。
我做了一个按钮来触发这个javascript函数:
function OpenPopupCenter() {
pageURL = 'http://www.google.com';
title = 'temp title';
w = (window.outerWidth * 0.67);
h = (window.outerHeight * 0.80);
var dualScreenLeft = typeof window.screenLeft !== "undefined" ? window.screenLeft : screen.left;
var dualScreenTop = typeof window.screenTop !== "undefined" ? window.screenTop : screen.top;
var width = window.innerWidth ? window.innerWidth :
document.documentElement.clientWidth ? document.documentElement.clientWidth : screen.width;
var height = window.innerHeight ? window.innerHeight :
document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height;
var left = ((width / 2) - (w / 2)) + dualScreenLeft -125;
var top = ((height / 2) - (h / 2)) + dualScreenTop;
var newWindow = window.open(pageURL, title, 'scrollbars=yes, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);
$(newWindow).ready(function () {
$("#lst-ib").val("Hello World");
});
打开的窗口显示 google,但我无法通过 id lst-ib 定位输入框并将字符串“Hello World”插入其中,我做错了吗,谁能指导我找到正确的解决方案或想出一个可行的方法。
【问题讨论】:
-
这听起来像是一项违反 JavaScript 跨域策略的任务,所以它可能不可行。请记住,可以控制另一个网站的网站可以访问敏感信息,例如银行信息或电子邮件。也许在“让我为你谷歌”网站上看到的“虚假”收购可以激发你的需求?
标签: javascript jquery target popupwindow