/ जावास्क्रिप्ट के साथ iframe src बदलना - जावास्क्रिप्ट, iframe, src

जावास्क्रिप्ट के साथ iframe src बदलना - जावास्क्रिप्ट, iframe, src

जब कोई किसी रेडियो बटन पर क्लिक करता है तो मैं एक iframe src को बदलने का प्रयास करता हूं। किसी कारण से मेरा कोड सही तरीके से काम नहीं कर रहा है और मुझे यह पता लगाने में परेशानी हो रही है कि क्यों। यही सब कुछ मेरे पास है:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Untitled 1</title>

<script>
function go(loc) {
document.getElementById("calendar").src = loc;
}
</script>
</head>

<body>
<iframe id="calendar" src="about:blank" width="1000" height="450" frameborder="0" scrolling="no"></iframe>

<form method="post">
<input name="calendarSelection" type="radio" onselect="go("http://calendar.zoho.com/embed/9a6054c98fd2ad4047021cff76fee38773c34a35234fa42d426b9510864356a68cabcad57cbbb1a0?title=Kevin_Calendar&type=1&l=en&tz=America/Los_Angeles&sh=[0,0]&v=1")" />Day
<input name="calendarSelection" type="radio" onselect="go("http://calendar.zoho.com/embed/9a6054c98fd2ad4047021cff76fee38773c34a35234fa42d426b9510864356a68cabcad57cbbb1a0?title=Kevin_Calendar&type=1&l=en&tz=America/Los_Angeles&sh=[0,0]&v=1")" />Week
<input name="calendarSelection" type="radio" onselect="go("http://calendar.zoho.com/embed/9a6054c98fd2ad4047021cff76fee38773c34a35234fa42d426b9510864356a68cabcad57cbbb1a0?title=Kevin_Calendar&type=1&l=en&tz=America/Los_Angeles&sh=[0,0]&v=1")" />Month
</form>

</body>

</html>

उत्तर:

उत्तर № 1 के लिए 95

इस मामले में, यह शायद इसलिए है क्योंकि आप यहां गलत कोष्ठकों का उपयोग कर रहे हैं:

document.getElementById["calendar"].src = loc;

होना चाहिए

document.getElementById("calendar").src = loc;

जवाब के लिए 49 № 2

शायद यह उपयोगी हो सकता है ... यह सादे HTML है - कोई जावास्क्रिप्ट नहीं:

<p>Click on link bellow to change iframe content:</p>
<a href="http://www.bing.com" target="search_iframe">Bing</a> -
<a href="http://en.wikipedia.org" target="search_iframe">Wikipedia</a> -
<a href="http://google.com" target="search_iframe">Google</a> (not allowed in inframe)

<iframe src="http://en.wikipedia.org" width="100%" height="100%" name="search_iframe"></iframe>

वैसे कुछ साइटें आपको iframe (सुरक्षा कारणों - क्लिकजैकिंग) में उन्हें खोलने की अनुमति नहीं देती हैं


16 के लिए उत्तर № 3

यहाँ यह करने के लिए jQuery तरीका है:

$("#calendar").attr("src", loc);

जवाब के लिए 6 № 4

The onselect होना चाहिए onclick। यह कीबोर्ड उपयोगकर्ताओं के लिए काम करेगा।

मैं भी जोड़ने की सलाह दूंगा <label> "दिन", "महीना", और "वर्ष" के पाठ को टैग करना, जिससे उन्हें क्लिक करने में आसानी हो। उदाहरण कोड:

<input id="day" name="calendarSelection" type="radio" onclick="go("http://calendar.zoho.com/embed/9a6054c98fd2ad4047021cff76fee38773c34a35234fa42d426b9510864356a68cabcad57cbbb1a0?title=Kevin_Calendar&type=1&l=en&tz=America/Los_Angeles&sh=[0,0]&v=1")"/><label for="day">Day</label>

मैं भी विशेषता के बीच रिक्त स्थान को हटाने की सिफारिश करूंगा onclick और मान, हालांकि इसे ब्राउज़र द्वारा पार्स किया जा सकता है:

<input name="calendarSelection" type="radio" onclick = "go("http://calendar.zoho.com/embed/9a6054c98fd2ad4047021cff76fee38773c34a35234fa42d426b9510864356a68cabcad57cbbb1a0?title=Kevin_Calendar&type=1&l=en&tz=America/Los_Angeles&sh=[0,0]&v=1")"/>Day

होना चाहिए:

<input name="calendarSelection" type="radio" onclick="go("http://calendar.zoho.com/embed/9a6054c98fd2ad4047021cff76fee38773c34a35234fa42d426b9510864356a68cabcad57cbbb1a0?title=Kevin_Calendar&type=1&l=en&tz=America/Los_Angeles&sh=[0,0]&v=1")"/>Day

जवाब के लिए 5 № 5

यह भी काम करना चाहिए, हालांकि src बरकरार रहेगा:

document.getElementById("myIFrame").contentWindow.document.location.href="http://myLink.com";

जवाब के लिए 0 № 6

यहाँ मेरा अद्यतन कोड है। यह ठीक काम करता है और यह आपकी मदद कर सकता है।

<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Untitled 1</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script type="text/javascript">
function go(loc) {
document.getElementById("calendar").src = loc;
}
</script>
</head>

<body>
<iframe id="calendar" src="about:blank" width="1000" height="450" frameborder="0" scrolling="no"></iframe>

<form method="post">
<input name="calendarSelection" type="radio" onclick="go("http://calendar.zoho.com/embed/9a6054c98fd2ad4047021cff76fee38773c34a35234fa42d426b9510864356a68cabcad57cbbb1a0?title=Kevin_Calendar&type=1&l=en&tz=America/Los_Angeles&sh=[0,0]&v=1")" />Day
<input name="calendarSelection" type="radio" onclick="go("http://calendar.zoho.com/embed/9a6054c98fd2ad4047021cff76fee38773c34a35234fa42d426b9510864356a68cabcad57cbbb1a0?title=Kevin_Calendar&type=1&l=en&tz=America/Los_Angeles&sh=[0,0]&v=1")" />Week
<input name="calendarSelection" type="radio" onclick="go("http://calendar.zoho.com/embed/9a6054c98fd2ad4047021cff76fee38773c34a35234fa42d426b9510864356a68cabcad57cbbb1a0?title=Kevin_Calendar&type=1&l=en&tz=America/Los_Angeles&sh=[0,0]&v=1")" />Month
</form>

</body>

</html>

-1 उत्तर № 7 के लिए

आप जावास्क्रिप्ट में आईफ्रेम बनाकर इसे हल कर सकते हैं

  document.write(" <iframe  id="frame" name="frame" src="" + srcstring + "" width="600"  height="315"   allowfullscreen></iframe>");