I'm trying to open a .pdf file in separate tab/window. It's working, but it opens two windows to show the .pdf.The code I used is as follows.
LinkButton btn = (LinkButton)(sender);
string value = btn.CommandArgument;
imfImageFile = LocalStaticData.UniImageResult;
string path = imfImageFile.WindowsPath;
if (path != "")
{
Session["OpenPDFImage"] = path;
ScriptManager.RegisterStartupScript(Parent.Page, GetType(),
Guid.NewGuid().ToString(), "openPdf(\"../InvoiceReport.aspx\" );", true);
}
JavaScript:
function openPdf(href) {
window.open(href);
}
Ok so two issues - I think Emanuele Greco is right that it is being called twice in your page cycle. The second issue is that you are giving it a unique code every time. You should be putting in the same code (not Guid.NewGuid()) to make sure the script only gets added once.
E.g.
LinkButton btn = (LinkButton)(sender);
string value = btn.CommandArgument;
imfImageFile = LocalStaticData.UniImageResult;
string path = imfImageFile.WindowsPath;
if (path != "")
{
Session["OpenPDFImage"] = path;
ScriptManager.RegisterStartupScript(Parent.Page, GetType(),
"InvoiceReportPDFOpenScript", "openPdf(\"../InvoiceReport.aspx\" );", true);
}
Related
I have a significant amount of external links on my website in this format:
website.com/product/[variable]
I need these links to somehow pass through “myaffiliatelink.com” before being redirected to website.com/product/[variable].
Is this possible using .htaccess or Javascript?
I looked into using .htaccess, but seems I would need to do this individually. Is there a way to set a rule such that any external link using "website.com/product/[variable]" should pass through "myaffiliatelink.com" first?
// catch every click on the page
document.addEventListener("click", e => {
const target = e.target;
if (target.tagName === 'A' && target.href.indexOf("website.com") !== -1) {
// prevent the <a> tag from navigating
e.preventDefault();
const lastSlash = target.href.lastIndexOf('/');
if (lastSlash > 0) {
const variable = target.href.substring(lastSlash + 1);
// use the commented code below, or a window.open
//location.href = "https://myaffiliatelink.com/"+variable;
// for demonstration
console.log("https://myaffiliatelink.com/" + variable);
}
}
})
Product
<p>should pass through "myaffiliatelink.com"</p>
I am trying to open a new window and execute a javascript code on the new page.
I'm not really sure why it doesn't execute the code - maybe it's not possible like this - anyway, the new window opens but the javascript doesn't get executed.
Here is my code:
var nstart = window.open("http://examplepage.html");
function loginnow(){
var htmlstring = "javascript: var zTextFields = window.document.getElementsByTagName(\"input\"); for (var i=0; i < zTextFields.length; i++) {thefield=zTextFields[i].name; if (!thefield) thefield=zTextFields[i].id; if (thefield == \"login\") zTextFields[i].value=\"_ext_cancom\"; if (thefield == \"password\")zTextFields[i].value=\"canfinag?!\";} window.document.getElementById(\"sign-in\").click();";
nstart.location.href = htmlstring;
}
nstart.addEventListener('load', loginnow, true);
Is it even possible to execute code like this? Please help ^-^
I'm also using '\' as an escape character so I can use " in the string -> \"
When I replace the \" with " and directly inject it into the page the script works fine...
Maybe you can add the javascript you want to execute in the new new page, and then make it run when document ready. So you will can just open the new page, JS will run automatically
If the new window is on the same domain you can access the contents by doing something like this.
var nstart = window.open("http://examplepage.html");
function loginnow() {
var zTextFields = nstart.document.getElementsByTagName("input");
for (var i=0; i < zTextFields.length; i++) {
thefield=zTextFields[i].name;
if (!thefield)
thefield=zTextFields[i].id;
if (thefield == "login")
zTextFields[i].value="_ext_cancom";
if (thefield == "password")
zTextFields[i].value="canfinag?!";
}
nstart.document.getElementById("sign-in").click();
}
nstart.addEventListener('load', loginnow, true);
You shouldn't really try to inject code onto the new window but you can access the dom and run javascript from the parent window.
I am trying to open new page with full screen. Below size is the my screen resolution. Still I have to click on re-sizable button on the browser to expand it to full screen.
How do I open it fill screen without clicking on re-sizeble?
Helper.Redirect("resource.aspx", "_blank",
"menubar=0,scrollbars=1,width=1366,height=768,top=10")
Method
Public Shared Sub Redirect(url As String, target As String, windowFeatures As String)
Dim context As HttpContext = HttpContext.Current
If ([String].IsNullOrEmpty(target) OrElse target.Equals("_self", StringComparison.OrdinalIgnoreCase)) AndAlso [String].IsNullOrEmpty(windowFeatures) Then
context.Response.Redirect(url)
Else
Dim page As Page = DirectCast(context.Handler, Page)
If page Is Nothing Then
Throw New InvalidOperationException("Cannot redirect to new window outside Page context.")
End If
url = page.ResolveClientUrl(url)
Dim script As String
If Not [String].IsNullOrEmpty(windowFeatures) Then
script = "window.open(""{0}"", ""{1}"", ""{2}"");"
Else
script = "window.open(""{0}"", ""{1}"");"
End If
script = [String].Format(script, url, target, windowFeatures)
ScriptManager.RegisterStartupScript(page, GetType(Page), "Redirect", script, True)
End If
End Sub
I tried 'fullscreen=yes, scrollbars=yes,location=yes,resizable=yes' parameters. It did not work.
Try:
window.open('newWin.html','NewWindow','fullscreen=yes');
Source:
Here
I had this same problem is simples just change this
Dim script As String
If Not [String].IsNullOrEmpty(windowFeatures) Then
script = "window.open(""{0}"", ""{1}"", ""{2}"");"
Else
script = "window.open(""{0}"", ""{1}"");"
End If
For this:
if (!String.IsNullOrEmpty(windowFeatures))
{
script = #"var w = window.open(""{0}"", ""{1}"", ""{2}""); w.moveTo(0,0); w.resizeTo(screen.width,screen.height-40);";
}
else
{
script = #"var w = window.open(""{0}"", ""{1}""); w.moveTo(0,0); w.resizeTo(screen.width,screen.height-40);";
if you want to is just put the property resizeto and moveTo
I am opening the window like this
var MyArgs = new Array(ParmA, ParmB, ParmC, ParmD, ParmE, ParmF);
var leftpost = getWindow_TotalWidth() - 1000 - 100;
var WinSettings1 = "dialogHeight:580px; dialogWidth:950px;edge:Raised; center:Yes; resizable:No; status: No;dialogLeft:" + leftpost + ";dialogTop:253px";
var MyArgs = window.showModalDialog("../Accounts/LedgerAdd.aspx?LedgerCode=" + MyArgs[1].toString().split("~")[0] + "&Popup=1", MyArgs, WinSettings1);
I would like to close the window based on condition. I have tried so many ways like
If Not Convert.ToDecimal(HidOpeningBalance.Value) = Convert.ToDecimal(TxtOpeningBalance.Text) Then
Dim LedgerID As Integer = Request.QueryString("LedgerCode")
Dim dtTransactionCount As DataTable = Grid.GetDataTable("sp_checkForAnyTransaction", LedgerID)
If dtTransactionCount.Rows.Count > 0 Then
LblError.Text = "You can not change Opening Balance after transactions made on this ledger."
Exit Sub
Else
Call FnUpdate()
Page.ClientScript.RegisterStartupScript([GetType](), "Javascript", "javascript:CloseWindow();", True)
End If
Else
LblError.Text = ""
Call FnUpdate()
Page.ClientScript.RegisterStartupScript([GetType](), "Javascript", "javascript:window.close();", True)
'Response.Write("<script language='javascript'>self.close();</script>")
'Page.ClientScript.RegisterStartupScript([GetType](), "Javascript", "javascript:CloseWindow();", True)
End If
my closeWindows function is
function CloseWindow() {
window.close();
}
If I call the function on onClientClick event, the popup is closing. But if I try to close it from code behind, the window is not closing. I have tried those three ways(I have commented in my code).
Please review this solution in the link provided.
http://forums.asp.net/t/993380.aspx?Close+Window+that+opens+with+window+showModalDialog
as you will see the solution became:
<base target="_self">
I'm just getting into javascript and so far enjoying the logic behind it but i have an issue with Firefox. basicly im generating my javascript from within a php function and its a NON SECURE pin code auth script.
So my php creates a call that passes variables pin number included, when called a modal popup with pinpad opens and the user inputs 4 digits, the pinpad onclick function adds the digits into a password field and after 4 clicks it compares it to a hidden field on the pinpad form, if it matches it calls another generated function to complete the success action, if no match pinpad frame turns red and a bypass button is enabled or they can try again.
This all works fine in Chrome, Opera and even IE but in Firefox it calls the success function after 4 digits even if they don't match the pin field.
Why could this be? Below is the function, but please remember I'm new so it could possibly be better written.
function add(text) {
var TheTextBox = document.pinform.elements['pin'];
var pincheckbox = document.pinform.elements['pincheck'];
var sidbox = document.pinform.elements['sid'];
TheTextBox.value = TheTextBox.value + text;
if (TheTextBox.value.length == 4) {
if (pinform.pin.value == pinform.pincheck.value) {
var pinn = document.getElementById('sid').value;
eval('pinpass' + pinn + '();');
} else {
document.getElementById("bypass").innerHTML = "Bypass";
document.getElementById("bypass").disabled = false;
document.getElementById("calc").style.backgroundColor = 'red';
TheTextBox.value = '';
return false;
}
}
}
Found the answer by trial and error as usual lol.
i need to add document. in front of pinform.pincheck.value and pinform.pin.value
Thanks for the help offered.
Nick
if (TheTextBox.value.length == 4) {
if (doucment.pinform.pin.value == document.pinform.pincheck.value) {
var pinn = document.getElementById('sid').value;
eval('pinpass' + pinn + '();');
} else {