需要帮助 - javascript - 在页面加载后设置选择值 [英] NEED HELP - javascript - set select value after page load

查看:50
本文介绍了需要帮助 - javascript - 在页面加载后设置选择值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我无法解决此问题。

我有一个包含iFrame和基本选择按钮的页面。单击链接时,iFrame将定向到外部页面,其中包含2个选择。我需要能够设置两个选择的值。

这就是我所拥有的:



Hello, I'm having trouble getting this to work.
I have a page that holds an iFrame and a basic select and button. When the Link is clicked, the iFrame is directed to an external page which has 2 selects in it. I need to be able to set the value some how of both of those selects.
Here's what I have:

<html>
<head>
<script>
function test() {
	document.getElementById('frame').src = "https://www.vagaro.com/studio21salons#online-scheduling";
}
function frame_loaded() {
	var iFrameDocument = this.contentDocument || this.contentWindow.document;
	var theSelectTag = iFrameDocument.getElementById('cboSalonServices');
	var theValue = "5606867";
	theSelectTag.value = theValue;
}
</script>
</head>
<body>
Service:
<select id="mySelect" size="4">
  <option>Taper Fade</option>
  <option>Loc Fade</option>
  <option>Designer Cut</option>
</select>
<a href="javascript:test();">Link</a>
<br/>
<iframe id="frame" style="width:1000px;height:1000px;" src="http://www.w3schools.com" onLoad="frame_loaded()"></iframe>
</body>
</html>





我的尝试:



我我试过在谷歌搜索javascript,php和java解决方案,但没有一个会工作。我也无法访问位于iFrame内的页面的代码。



What I have tried:

I've tried searching on google for javascript, php and java solutions but none will work. I also don't have access to the code for the page that sits inside the iFrame.

推荐答案

你不能。



从一个域加载的脚本无法访问或修改从其他域加载的文档。



这是浏览器强加的基本安全限制,并且没有办法解决它。如果有的话,没有什么可以阻止evilhackers.com在隐藏的框架中加载您的网上银行网站,阅读您的银行帐户详细信息,并将所有资金转移到他们的帐户。
You cannot.

Script loaded from one domain cannot access or modify a document loaded from a different domain.

This is a fundamental security restriction imposed by the browser, and there is no way around it. If there were, there would be nothing to stop "evilhackers.com" from loading your online banking site in a hidden frame, reading your bank account details, and transferring all of your money to their account.


这篇关于需要帮助 - javascript - 在页面加载后设置选择值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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