Iframe javascript src setting opens in entire window - iframe

I have defined an IFrame in HTML.
From JavaScript I am trying to change the URL(src attribute) of the IFrame. It's working fine with most of the URLs. But when I try to set an eBay item URL more than once it opens in entire window.
Here is my code:
<html>
<head>
<script type="text/javascript">
function seturl(){
var txt=document.getElementsByName("txt");
document.getElementById('testframe').src = txt[0].value;
}
</script>
</head>
<body>
<iframe id="testframe" width= "700" height="500" >
</iframe>
<input type="text" name="txt" width="700"/>
<input type="button" value="Click me!" onclick="seturl()" />
</body>
</html>
Is there any solution to avoid opening in entire page for this eBay items URL?
http://cgi.ebay.com/Apple-iPad-Wi-Fi-32GB-BRAND-NEW-NO-RESERVE_W0QQitemZ220725228457QQcategoryZ171485QQcmdZViewItem

You are not allowed to do so.
It would seem that what you want to do is a violation of the UA.
http://pages.ebay.com/help/policies/user-agreement.html

Related

Ajax.BeginForm OnBegin not firing (ASP.NET MVC5 application)

I've been trying to get a Javascript function to fire when my page's AJAX processing is triggered without success. Most of my time has been spent trying to get the OnBegin AjaxOption value working, but I have spent time with the global JQuery .ajaxSend handler as well (which I believe might not be compatible with ASP.NET MVC), both without success.
I've reduced my page to something pretty simple. My Index.cshtml for the project is:
#using SalePointWebItemInquiry.Controllers
#using System.Web.Mvc.Ajax
#{
ViewBag.Title = "Home Page";
}
#Scripts.Render("~/bundles/jquery", "~/bundles/jqueryval")
<script type="text/javascript">
function TestFunction() {
alert("Calling testfunction.");
}
</script>
#using (Ajax.BeginForm("PressButton",
"Home",
new AjaxOptions
{
OnBegin = "TestFunction"
}))
{
<div>
<input class="btn btn-default" type="submit" id="1" name="buttonType" value="Enter" />
</div>
}
The page that this renders is:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Home Page - My ASP.NET Application</title>
<link href="/Content/bootstrap.css" rel="stylesheet" />
<link href="/Content/site.css" rel="stylesheet" />
<script src="/Scripts/modernizr-2.6.2.js"></script>
</head>
<body>
<div class="container body-content bordered">
<script src="/Scripts/jquery-1.10.2.js"></script>
<script src="/Scripts/jquery.validate.js"></script>
<script src="/Scripts/jquery.validate.unobtrusive.js"></script>
<script type="text/javascript">
function TestFunction() {
alert("Calling testfunction.");
}
</script>
<form action="/Home/PressButton" data-ajax="true" data-ajax-begin="TestFunction" id="form0" method="post">
<div>
<input class="btn btn-default" type="submit" id="1" name="buttonType" value="Enter" />
</div>
</form>
<footer>
<div class="row">
<div class="col-md-5">
<p>© 2015 - Application</p>
</div>
<div class="col-md-7 text-right">
Version: Put version here
</div>
</div>
</footer>
</div>
<script src="/Scripts/jquery-1.10.2.js"></script>
<script src="/Scripts/bootstrap.js"></script>
<script src="/Scripts/respond.js"></script>
<!-- Visual Studio Browser Link -->
<script type="application/json" id="__browserLink_initializationData">
{"appName":"Internet Explorer","requestId":"d2eef5342ac64f3db1545856102f4a6f"}
</script>
<script type="text/javascript" src="http://localhost:53954/45ae7332668647b5a3795d87cd6ba1a9/browserLink" async="async"></script>
<!-- End Browser Link -->
</body>
</html>
Does anyone have any thoughts on why the TestFunction() Javascript function isn't firing when I click the ENTER button?
Solution:
Thanks for the help :). I wasn't properly referencing jquery.unobtrusive-ajax.js. The direct solution to my problem was to use Nuget to retrieve a Javascript package that wasn't local using this command at Nuget console:
Install-Package Microsoft.jQuery.Unobtrusive.Ajax
Since I didn't have jquery.unobtrusive-ajax.js locally, all of my attempts to reference it locally failed. I may have tried a CDN reference once or twice, but that never worked out and I had a lot of theories as to the cause of the problem at the time.
I didn't even have to change the code. This code in BundleConfig.cs automatically included the file once I had retrieved it:
bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
"~/Scripts/jquery.unobtrusive*",
"~/Scripts/jquery.validate*"));
You have duplicated
<script src="/Scripts/jquery-1.10.2.js"></script>
Remove the second one and then you also need to add jquery.unobtrusive-ajax.js in order for Ajax.BeginForm() to work (other wise you just making a normal submit - and therefore TestFunction() will never be called)
Looks like you are loading your script before JQuery can load. Scripts need to load at the bottom of the page just before the body tag and after JQuery loads.
Please try
#section Scripts
{
<script type="text/javascript">
function TestFunction() {
alert("Calling testfunction.");
}
</script>
}
This will place the script after JQuery loads.

Generating a Simple QR-Code with just HTML

I came across this APIserver to generate the QRCode but I was wondering is it possible to just use HTML to generate the QRcode for example this is what I was thinking
<input id="text" type="text" value="Please Enter Your NRIC or Work Permit" style="Width:20%"/>
<img src="https://api.qrserver.com/v1/create-qr-code/?data=HelloWorld&size=100x100" alt="" title="HELLO" />
In the "title" I believe it is where you will write your text and the QR code would generate, I was wondering how can I create a text box for me to key in the value directly on a website.
Were you thinking of something like this? https://jsfiddle.net/v7d6d1ps/
Your HTML can be similar to what you have but with added onblur event. Only HTML cannot do this, so I have added jQuery/JavaScript combination.
<html>
<head>
<title>Testing QR code</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script type="text/javascript">
function generateBarCode()
{
var nric = $('#text').val();
var url = 'https://api.qrserver.com/v1/create-qr-code/?data=' + nric + '&size=50x50';
$('#barcode').attr('src', url);
}
</script>
</head>
<body>
<input id="text" type="text"
value="NRIC or Work Permit" style="Width:20%"
onblur='generateBarCode();' />
<img id='barcode'
src="https://api.qrserver.com/v1/create-qr-code/?data=HelloWorld&size=100x100"
alt=""
title="HELLO"
width="50"
height="50" />
</body>
</html>
Copy and paste this into an HTML file on your desktop. Type in the text box 12345 and hit tab. Notice that the QR code will update.

Issue adjusting iframe height when opened as popup using ModalPopupextender

I am using a ModalPopupextender Ajax Control to open aspx page in a modal Popup. aspx page is opened in a iframe as shown in below code.The content which is loaded in iframe is dynamic hence I cannot give a fixed height to iframe. I want that I should be able to adjust the height as per the content every time popup is being opened. I have a function to resize the iframe height and I am using that successfully on my other pages where iframe gets populated in the window itself but not able to adjust the height when iframe is opened in a POPUP. I have already tried window onload, iframe onload events without any success.
<asp:ModalPopupExtender ID="ModalPopupExtender2" BackgroundCssClass="transparentBG"
runat="server" CancelControlID="ButtonCancel" OkControlID="ButtonDone"
TargetControlID="btnAddNew" PopupControlID="DivAddWindow" Drag="true" >
</asp:ModalPopupExtender>
<div class="popup_Buttons" style="display: none">
<input id="ButtonDone" value="Done" type="button" />
<input id="ButtonCancel" value="Cancel" type="button" />
</div>
<div id="DivAddWindow" style="display: none;">
<iframe id="IframeEdit" scrolling="no" src="MasterPage.aspx" width="700px">
</iframe>
</div>
I would really appreciate if somebody can lead me the solution to resolve this.
Try this:
<iframe id="IframeEdit" onload="iframeLoaded()" scrolling="yes" src="MasterPage.aspx" width="700px">
</iframe>
following javascript function would get height from the iframe content.
<script type="text/javascript">
function iframeLoaded() {
var iFrameID = document.getElementById('IframeEdit');
if (iFrameID) {
iFrameID.height = "";
iFrameID.height = iFrameID.contentWindow.document.body.scrollHeight + "px";
}
}
</script>
I checked it in even ModalPopupextender, it works.

Firefox is not responding to the click. No error in Firebug and nothing is happening. Chrome it is working fine

This is the code i used to print the pdf inside and iframe.
But in Firefox its not even responding. No error in firebug.
In chrome its working fine.
Please help me.
<html>
<head>
<script type="text/javascript">
function Printpd(pdf)
{
pdf.focus();
pdf.print();
}
</script>
</head>
<body>
<iframe name="myFrame" id="myFrame" width="600" height="400" src="uploadedfiles/DPA%20Quick%20Reference%20Guide.pdf""></iframe>
<input type="button" value="Print IFRAME" onclick="Printpd(myFrame);" />
</body>
</html>
This will resolve the IFrame reference, it won't solve your printing issue, see link from #Nikki9696 for that:
<input type="button" value="Print IFRAME"
onclick="Printpd(document.getElementById('myFrame'));" />

Is it possible to load whole html page without iframe but using jQuery?

Suppose I have following html page.
<html>
<head>
<link type="text/css" rel="Stylesheet" href="css/some.css" />
</head>
<body>
<input type="button" value="test" id="btnTest" name="btnTest"/>
<!--Script Section start-->
<script type="text/javascript" src="js/jquery/jquery-1.4.1.js"></script>
<script type="text/javascript">
function someFunction()
{
alert("hi");
}
</script>
<!--Script Section end-->
</body>
</html>
and I want above whole page to get loaded in another page without the help of iframe when I click on top menu of that page.
this is possible when both pages are on the same server. You should take a look at jQuery's .load() function: http://api.jquery.com/load/
You can also include only some part of the page by using selectors inside load statement, like so
$('#result').load('ajax/test.html div:first');

Resources