How to create a function to generate link by opening new window - javascript

I've tried to create function of link that can open new window..currently I used
Function genLink(req_id)
genLink = " onclick=""location.href='order_view.asp?bill_id=" & req_id & "' "" "
End function
it's work but not open new window for me ..
So i've searched found that it need to be use window.open instead so I do like below.. But it's not work..
Function genLink(req_id)
genLink = " onclick=""window.open='order_view.asp?bill_id=" & req_id & "' ,'_blank' "" "
End function
so could you please tell me what did I do wrong. ?

Try:
genLink = " onclick=""window.open('order_view.asp?bill_id=" & req_id & "' , null, '_blank' )"" "
window.open() is a method, and the 2nd param it's the name.
window.open(URL,name,specs,replace)

Related

How to add target="_blank" into a document.write?

I am doing this on chrome dev tools. The error message I am getting is, "Can't open same-window link to "URL"; try target="_blank". I can't figure out how to incorporate that into this Javascript.
document.write=function(s){
var scripts = document.getElementsByTagName('script');
var lastScript = scripts[scripts.length-1];
lastScript.insertAdjacentHTML("beforebegin", s);
}
var txt = "Let's Start";
document.write("<p>Link: " + txt.link("beginning.html") , "_blank" + "</p>");
First: The link() method is not standard, and may not work as expected in all browsers.
Second: There is no correct way to do it with String object https://www.w3schools.com/jsref/jsref_link.asp
Third:
var link = "<a href='beginning.html' target='_blank'>Let's Start</a>";
document.write("<p>Link: " + link + "</p>");
Have you tried changing that to this line:
document.write("<p>Link: " + txt.link("beginning.html") , "_blank" + "</p>");
to
document.write("<p>Link: " + txt.link("beginning.html") + " _blank" + "</p>");
Strictly a guess as we assume .link() is returning a string (?)

display alert message after redirect

I have a button that executes a function:
$("#btnRemove").click(function () {
var name= $("#editAccountName").val();
if (confirm("Are you sure you want to mark " + "''" + name + "''" + " as innactive?")) {
saveAccount(false);
window.location.href = "/RxCard/Search";
}
alert (name + "was marked innactive.")
});
I need the alert to show after the user is redirected to "/Rxcard/Search"
what do i need to change in my code to get it working like that?
on a side note, how would do the same but with a CSS customized alert?
Thanks.
Instead of putting your alert in this code, you need to put it into the script behind Search page. Now you can add a url parameter and then in there check it and show the alert if that parameter is set:
if (confirm("Are you sure you want to mark " + "''" + name + "''" + " as innactive?")) {
saveAccount(false);
window.location.href = "/RxCard/Search?name=" + name;
}
And then add this somewhere (doesn't matter that much):
$.urlParam = function(name){
var results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(window.location.href);
if (results==null){
return null;
}
else{
return results[1] || 0;
}
}
And at last this code goes into your search page code:
function() {
if($.urlParam('name') == true){
alert (name + "was marked innactive.");
}
}();
You cannot run an alert after the location.href has changed because it causes the browser to refresh. Once refreshed, your script is no longer running.
You would need to move your alert script into your search page and perhaps pass the name as a querystring arguement.
You could store the name value using localstorage. The value can be evaluated after the redirection so you can display the dialog with the stored value (if any)
You can't style your alert dialog but you can always create a modal dialog from scratch or by using a web framework / library.

Calling Mailto inside body of another mailto

Is that possible to give mailto inside the body of another mailto?
I have vb.net code through which I am opening outlook window.
I have the below code,
sMsg = User.Redirect("mailto:" + legRev + "& CC=" + cc + "&Subject= " + OuterSubject + "&body=" + Body)
ScriptManager.RegisterStartupScript(Me.Page, Me.GetType(), "showalert", sMsg, True)
Public Function Redirect(ByVal PageName As String) As String
Dim sb As New StringBuilder()
sb.Append("window.location.href='" + PageName + "'; ")
Return sb.ToString()
End Function
In the body string I have
mailto:" + innerTo + "&CC=" + innerCC + "&Subject= " + innerSubject
Problem is I am getting a mail opened with subject set to 'innerSubject' instead of 'OuterSubject'
I think my OuterSubject is getting replaced by InnerSubject.
The body string needs to be escaped with a function like Uri.EscapeDataString. Your URI should end up having only one ? in it, and none of the & characters from your body should be visible.
Example:
mailto:john.doe#example.com?subject=Test+Message&body=mailto%3Ajane.doe%40example.com%3Fcc%3Dbob%40bob.com%26subject%3DReply%2Bto%2Byou

Return a folder path using extendscript

Using extendscript, could anyone tell me how could open a dialog box, click on a folder to highlight it, then OK the dialog and return the path to that folder as a string.
Many thanks
Bob
Try it like this:
var myFolder = Folder.selectDialog ("Select a folder");
if(myFolder != null){
if(myFolder instanceof Folder){// <-- This is not really needed
alert("path: " + myFolder.path);
alert("fsName: " + myFolder.fsName);
alert("fullName: " + myFolder.fullName);
alert("name: " + myFolder.name);
}
}

How does phpmyadmin open a small window both in firefox and IE?

When you edit a datetime column via its datepickup,a window pops up instead of a new tab.
How to do it?
I tried window.open(..) but it just opens a new tab.
I don't know phpmyadmin in particular, but could it be:
window.showModalDialog(...);
showModalDialog("URL"[, arguments[, "features"]])
http://javascript.gakaa.com/window-showmodaldialog-4-0-5-.aspx
It calls a openCalendar function which looks like this:
function openCalendar(params, form, field, type, fieldNull) {
window.open("./calendar.php?" + params, "calendar", "width=400,height=200,status=yes");
dateField = eval("document." + form + "." + field);
dateType = type;
if (fieldNull != '') {
dateFieldNull = eval("document." + form + "." + fieldNull);
}
}
Basically just setting the width and height attributes (btw, if it's opening in a new tab, it's your browser that opens it that way, not the javascript).
You'll need to provide more than just the url: https://developer.mozilla.org/En/DOM/Window.open - take a look at the windowFeatures parameter. They happen to be using the following function:
function openCalendar(params, form, field, type) {
window.open("./calendar.php?" + params, "calendar", "width=400,height=200,status=yes");
dateField = eval("document." + form + "." + field);
dateType = type;
}

Categories

Resources