


Sample code sharing on how to use JavaScript to dynamically change the src attribute of an iframe
How to use JavaScript to dynamically change the src attribute of an iframe. Sample code sharing
<iframe id="xx"></iframe> <iframe id="yy"></iframe> <script> var xxObj = document.frames; xxObj[0].src="index.htm"; </script>
iframeID.location=newURL
<iframe id="myIframe"></iframe> <script language="javascript"> myIframe.src = "index.htm"; </script>
document.frames[0].location.href =url ;
window.frames["iframeName attribute"].location.href="xxxx.asp"
frames.youname.src = url;
<iframe id="xx" src=""></iframe> document.getElementById("xx").src="xx.htm";
or
document.getElementsByTagName("iframe")[0].src="xx.htm";
In my impression, cross-domain is not allowed
My admiration for everyone upstairs is like an endless river.
document.frames[0].navigate("about:blank");
The window object has the navigate() method to redirect to the specified URL. . .
The src of iframe can definitely be changed. It is estimated that the original poster failed because the obtained iframe object was incorrect.
top.document.all("Your iframe's ID/name").src=your address; This should be used in IE, but I recommend that for better compatibility, the iframe has both id and name. And to obtain the object, use the following compatibility code
function lib_bwcheck(){ this.ver=navigator.appVersion; this.agent=navigator.userAgent this.dom=document.getElementById?1:0 this.win = (navigator.appVersion.indexOf("Win")>0); this.xwin = (navigator.appVersion.indexOf("X11")>0); this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom)?1:0; this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom)?1:0; this.ie4=(document.all && !this.dom)?1:0; this.ie=this.ie4||this.ie5||this.ie6 this.mac=this.agent.indexOf("Mac")>-1 this.opera5=this.agent.indexOf("Opera 5")>-1 this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0; this.ns4=(document.layers && !this.dom)?1:0; this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5 || this.dom||false); this.width = null; this.height = null; return this } function getObjectById( ID ) { var bw = new lib_bwcheck(); if (bw.ns6) return document.getElementById(ID); else if (bw.ns) return document.layers[ID]; else return document.all[ID]; }
both
top.document.all("你的iframe的ID/name").src=你的地址;变成 getObjectById( "你的iframe的ID/name" ).src=你的地址;
According to the method provided by the heroes, you can change the url, thank you very much! Another problem I have here is that I first need to change the url of the parent page (without opening a new page), and then change the src of the iframe in the page. I hope you can provide further support!
The method I use is:
window.location =parentUrl; document.getElementById("upperPage").src=child1Url; document.getElementById("bottomPage").src=child2Url;
This way I cannot change the src attribute of the iframe. If I remove window.location =parentUrl;, I can change the src attribute! Please experts continue to enlighten me! Kindness without saying thanks! ! !
Are you sure there is an iframe like upperPage in the new page?
ice_berg16 (the dream-seeking scarecrow), can you give me a solution? I want to change the url of the current page, and also modify the src attribute of the iframe inside it. Thank you very much!
The above is the detailed content of Sample code sharing on how to use JavaScript to dynamically change the src attribute of an iframe. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



How to use WebSocket and JavaScript to implement an online speech recognition system Introduction: With the continuous development of technology, speech recognition technology has become an important part of the field of artificial intelligence. The online speech recognition system based on WebSocket and JavaScript has the characteristics of low latency, real-time and cross-platform, and has become a widely used solution. This article will introduce how to use WebSocket and JavaScript to implement an online speech recognition system.

Face detection and recognition technology is already a relatively mature and widely used technology. Currently, the most widely used Internet application language is JS. Implementing face detection and recognition on the Web front-end has advantages and disadvantages compared to back-end face recognition. Advantages include reducing network interaction and real-time recognition, which greatly shortens user waiting time and improves user experience; disadvantages include: being limited by model size, the accuracy is also limited. How to use js to implement face detection on the web? In order to implement face recognition on the Web, you need to be familiar with related programming languages and technologies, such as JavaScript, HTML, CSS, WebRTC, etc. At the same time, you also need to master relevant computer vision and artificial intelligence technologies. It is worth noting that due to the design of the Web side

In the operation process of the Meituan Takeout Merchant Edition, the setting of the starting delivery price is a crucial link. A reasonable starting delivery price can not only help merchants control costs, but also increase order amounts to a certain extent, thus increasing overall revenue. However, many merchants don’t know much about how to modify the minimum delivery price. So in the following article, the editor of this website will bring you detailed starting price setting guide for merchants. If you want to know more, come to the following article to find out! In the Meituan Takeout Merchant Center, log in and enter the store settings, then select store management. In the switch navigation at the top of the store management page, select delivery information, and then click Add Delivery Area to complete the operation. Once you add a location, the corresponding shipping costs will automatically appear. After completing your order, you will receive

WebSocket and JavaScript: Key technologies for realizing real-time monitoring systems Introduction: With the rapid development of Internet technology, real-time monitoring systems have been widely used in various fields. One of the key technologies to achieve real-time monitoring is the combination of WebSocket and JavaScript. This article will introduce the application of WebSocket and JavaScript in real-time monitoring systems, give code examples, and explain their implementation principles in detail. 1. WebSocket technology

Essential tools for stock analysis: Learn the steps to draw candle charts in PHP and JS. Specific code examples are required. With the rapid development of the Internet and technology, stock trading has become one of the important ways for many investors. Stock analysis is an important part of investor decision-making, and candle charts are widely used in technical analysis. Learning how to draw candle charts using PHP and JS will provide investors with more intuitive information to help them make better decisions. A candlestick chart is a technical chart that displays stock prices in the form of candlesticks. It shows the stock price

Introduction to how to use JavaScript and WebSocket to implement a real-time online ordering system: With the popularity of the Internet and the advancement of technology, more and more restaurants have begun to provide online ordering services. In order to implement a real-time online ordering system, we can use JavaScript and WebSocket technology. WebSocket is a full-duplex communication protocol based on the TCP protocol, which can realize real-time two-way communication between the client and the server. In the real-time online ordering system, when the user selects dishes and places an order

JavaScript and WebSocket: Building an efficient real-time weather forecast system Introduction: Today, the accuracy of weather forecasts is of great significance to daily life and decision-making. As technology develops, we can provide more accurate and reliable weather forecasts by obtaining weather data in real time. In this article, we will learn how to use JavaScript and WebSocket technology to build an efficient real-time weather forecast system. This article will demonstrate the implementation process through specific code examples. We

JavaScript tutorial: How to get HTTP status code, specific code examples are required. Preface: In web development, data interaction with the server is often involved. When communicating with the server, we often need to obtain the returned HTTP status code to determine whether the operation is successful, and perform corresponding processing based on different status codes. This article will teach you how to use JavaScript to obtain HTTP status codes and provide some practical code examples. Using XMLHttpRequest
